import { Global, Module } from '@nestjs/common';
import Redis from 'ioredis';
import configuration from '@/config/configuration';
import { ConfigModule } from '@nestjs/config';
import { RedisService } from './redis.service';

@Global()
@Module({
  imports: [ConfigModule],
  providers: [
    {
      provide: 'REDIS_CLIENT',
      useFactory: () => {
        return new Redis({
          host: configuration().redis.host,
          port: configuration().redis.port,
          password: configuration().redis.password,
        });
      },
    },
    RedisService,
  ],
  exports: [RedisService],
})
export class RedisModule {}
